package com.ebelter.bodyfatscale.ui.pager.main;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.TextView;

import com.ebelter.bodyfatscale.R;
import com.ebelter.bodyfatscale.common.Constants;
import com.ebelter.bodyfatscale.moudules.db.daos.HistoryMesureDataDao;
import com.ebelter.bodyfatscale.moudules.https.BaseJsonGenerator;
import com.ebelter.bodyfatscale.moudules.https.NetUtils;
import com.ebelter.bodyfatscale.moudules.https.interfaces.HttpResponse;
import com.ebelter.bodyfatscale.moudules.https.response.HttpsParameters;
import com.ebelter.bodyfatscale.moudules.https.response.OriginalParametersResponse;
import com.ebelter.bodyfatscale.ui.activity.GuestSelectActivity;
import com.ebelter.bodyfatscale.ui.activity.MainActivity;
import com.ebelter.bodyfatscale.ui.view.MyDashBoardView2;
import com.ebelter.bodyfatscale.ui.view.MyDashBoardView3;
import com.ebelter.bodyfatscale.ui.view.dialogs.WeighTipDialog;
import com.ebelter.bodyfatscale.util.NumUtils;
import com.ebelter.bodyfatscale.util.ScaleBaseUtils;
import com.ebelter.bodyfatscale.util.SpecialText;
import com.ebelter.bodyfatscale.util.StringUtils;
import com.ebelter.bodyfatscale.util.ToastUtil;
import com.ebelter.bodyfatscale.util.UserSpUtil;
import com.ebelter.bodyfatscale.util.ViewUtils;
import com.ebelter.btlibrary.btble.impl.scale.model.ScaleMeasureResult;
import com.ebelter.btlibrary.btble.impl.scale.model.ScaleUser;
import com.ebelter.btlibrary.util.ULog;

import java.io.Serializable;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

/**
 * 未绑定提示页
 */

public class DashboardPager extends BasePagerMain {


    private static final String TAG = "DashboardPager";

    private ImageView ivUserIcon;//用户图标
    private TextView tvUserName;//用户名字
    private TextView tv_title_dashboard_pager;//用户名字

    private ImageView iv_title_dashboard_pager;

    private MyDashBoardView2 dbv;//转盘
    private MyDashBoardView3 dbv3_lb;//转盘
    private TextView tvBodyScore;//身体分数
    private TextView tvBodyAge;//身体年龄
    private TextView tvWeight;//体重
    private TextView tvFat;//体脂百分比
    private TextView tvBmi;//BMI
    private TextView tvBmr;//BMR
    private TextView tvVfl;//内脏脂肪水平
    private TextView tvMv;//肌肉质量
    private TextView tvBv;//骨量
    private TextView tvProtein;//蛋白质
    private TextView tvWr;//身体水分百分比
    private TextView tvSkeletal;//骨骼

    private TextView tvWeight2;//体重
    private TextView tvFat2;//体脂百分比
    private TextView tvBmi2;//BMI
    private TextView tvBmr2;//BMR
    private TextView tvVfl2;//内脏脂肪水平
    private TextView tvMv2;//肌肉质量
    private TextView tvBv2;//骨量
    private TextView tvProtein2;//蛋白质
    private TextView tvWr2;//身体水分百分比
    private TextView tvSkeletal2;//骨骼

    private BaseJsonGenerator mBaseJsonGenerator;

    public DashboardPager(Activity context) {
        super(context);
    }

    //boolean isConnectFlag;

    @Override
    protected int loadLayoutById() {
        return R.layout.pager_dashboard;
    }

    @Override
    public void initViews() {
        myHandle=new MyHandle();
        mBaseJsonGenerator = new BaseJsonGenerator();
        ivUserIcon = mRootView.findViewById(R.id.iv_user_icon);
        tvUserName = mRootView.findViewById(R.id.tv_user_name);
        tv_title_dashboard_pager = mRootView.findViewById(R.id.tv_title_dashboard_pager);
        iv_title_dashboard_pager = mRootView.findViewById(R.id.iv_title_dashboard_pager);
        setTime();

        ivUserIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent guestSelect = new Intent(getActivity(), GuestSelectActivity.class);
                getActivity().startActivityForResult(guestSelect, GuestSelectActivity.REQUEST_CODE);
//                Constants.isKgUnit=!Constants.isKgUnit;
//                setDisplayDbv(123.5f);
            }
        });


        View content = mRootView.findViewById(R.id.content_dashboard_pager);
        dbv = content.findViewById(R.id.dbv_dashboard_pager);
        dbv3_lb = content.findViewById(R.id.dbv_dashboard_pager3);

        if (Constants.isKgUnit) {
            ViewUtils.displayView(dbv);
            ViewUtils.hideView(dbv3_lb);
        } else {
            ViewUtils.displayView(dbv3_lb);
            ViewUtils.hideView(dbv);
        }


        tvBodyScore = content.findViewById(R.id.tv_body_score);


//        tvBodyScore.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                ULog.i(TAG,"-----tvBodyScore点击了一次");
//                isConnectFlag=!isConnectFlag;
//                setDashboardPagerConnectImage(isConnectFlag);
//            }
//        });


        tvBodyAge = content.findViewById(R.id.tv_body_age);

        tvWeight = content.findViewById(R.id.tv_weight_dashboard_pager);
        tvFat = content.findViewById(R.id.tv_fat_dashboard_pager);
        tvBmi = content.findViewById(R.id.tv_bmi_dashboard_pager);
        tvBmr = content.findViewById(R.id.tv_bmr_dashboard_pager);
        tvVfl = content.findViewById(R.id.tv_vfl_dashboard_pager);
        tvMv = content.findViewById(R.id.tv_mv_dashboard_pager);
        tvBv = content.findViewById(R.id.tv_bv_dashboard_pager);
        tvProtein = content.findViewById(R.id.tv_protein_dashboard_pager);
        tvWr = content.findViewById(R.id.tv_wr_dashboard_pager);
        tvSkeletal = content.findViewById(R.id.tv_skeletal_dashboard_pager);

        tvWeight2 = content.findViewById(R.id.tv_name_weight_dashboard_pager);
        tvFat2 = content.findViewById(R.id.tv_name_fat_dashboard_pager);
        tvBmi2 = content.findViewById(R.id.tv_name_bmi_dashboard_pager);
        tvBmr2 = content.findViewById(R.id.tv_name_bmr_dashboard_pager);
        tvVfl2 = content.findViewById(R.id.tv_name_vfl_dashboard_pager);
        tvMv2 = content.findViewById(R.id.tv_name_mv_dashboard_pager);
        tvBv2 = content.findViewById(R.id.tv_name_bv_dashboard_pager);
        tvProtein2 = content.findViewById(R.id.tv_name_protein_dashboard_pager);
        tvWr2 = content.findViewById(R.id.tv_name_wr_dashboard_pager);
        tvSkeletal2 = content.findViewById(R.id.tv_name_skeletal_dashboard_pager);

        ScaleBaseUtils.setTextViewSize1(getActivity(),tvWeight2,tvFat2,tvBmi2,tvBmr2,tvVfl2,tvMv2,tvBv2,tvProtein2,tvWr2,tvSkeletal2);

    }


    //设置时间
    private void setTime() {
        Calendar calendar = Calendar.getInstance();
        tv_title_dashboard_pager.setText(SpecialText.formatDateStampString0(calendar.getTime().getTime()));

    }

    public void updateUserNick() {
        ScaleUser user = ScaleUser.getUser();
        tvUserName.setText(user.getNike());
        ivUserIcon.setImageResource(user.getSex() == 0 ? R.drawable.icon_male_main : R.drawable.icon_female_main);
    }

    @Override
    public void initData(Object data) {
        ULog.i(TAG, "------initData----data = " + data);
        ULog.i(TAG, "------ScaleUser.getUser() = " + ScaleUser.getUser());
//
//        ###    ------initData----data = MeasureResult{btId='00:01:00:00:00:00:02', age=28, sex=0, mac='null', measureTime='2018-05-08 14:31:43',
// resistance=436.0, fat=14.6, weight=66.4, waterRate=57.392086, bmr=1596.2145, visceralFat=4.5, muscleVolume=30.3908,
//                skeletalMuscle=53.61961, boneVolume=3.069252, bmi=21.0, protein=23.4, bodyScore=81.0, bodyAge=20.0, weightUnit='kg', fatUnit='%'}

        ScaleUser user = ScaleUser.getUser();
        tvUserName.setText(user.getNike());
        int imgId = R.drawable.icon_male_main;
        if (user.getIcon() == null) {
            if (user.getSex() != 0) {
                imgId = R.drawable.icon_female_main;
            }
            ivUserIcon.setBackgroundResource(imgId);
        } else {
            ivUserIcon.setImageBitmap(user.getIcon());
        }

        if (data == null || !(data instanceof ScaleMeasureResult)) {
            onNoResult();
            return;
        }
        ScaleMeasureResult result = (ScaleMeasureResult) data;
        result = ScaleBaseUtils.checkScaleMeasureResult18old(result);
        displayUploadMeasureData(result);
    }

    @Override
    public void switchUnitUpdate() {
        onNoResult();
    }

    private float numFatmat(float num) {
        return NumUtils.numBaoLiuWei(num, 1);
    }

    private WeighTipDialog mWeighTipDialog;

    private void displayUploadMeasureData(final ScaleMeasureResult result) {
        if (result == null) {
            return;
        }
        ULog.i(TAG, "接收到测量数据--" + result.toString());
//
//        ###    ------initData----data = MeasureResult{btId='00:01:00:00:00:00:02', age=28, sex=0, mac='null', measureTime='2018-05-08 14:31:43',
// resistance=436.0, fat=14.6, weight=66.4, waterRate=57.392086, bmr=1596.2145, visceralFat=4.5, muscleVolume=30.3908,
//                skeletalMuscle=53.61961, boneVolume=3.069252, bmi=21.0, protein=23.4, bodyScore=81.0, bodyAge=20.0, weightUnit='kg', fatUnit='%'}

        final float weight = numFatmat(result.getWeight());
        if (weight <= 0) {
            return;//如果体重都等于0时就没必要往上传了
        }
        final float fat = numFatmat(result.getFat());//脂肪率
        final float bmi = numFatmat(result.getBmi());
        final int bmr = (int) result.getBmr();
        final float vf = numFatmat(result.getVisceralFat());//内脂等级
        final float muscleMass = numFatmat(result.getMuscleVolume());
        final float boneMass = numFatmat(result.getBoneVolume());
        final float protein = numFatmat(result.getProtein());
        final float waterRate = numFatmat(result.getWaterRate());
        final float skeletalMuscle = numFatmat(result.getSkeletalMuscle());
        final int bodyScore = (int) result.getBodyScore();
        final int bodyAge = (int) result.getBodyAge();
        // weight=65;

        if (ScaleUser.getUser().getAge()<18){
            ToastUtil.show(R.string.select_age_tip);//未满18岁测脂错误提示
        }

        if (Constants.isGuestModel || TextUtils.equals("0", result.getBtId())) {//如果是访客模式，只显示出数据在界面上
            setDisplayDbv(weight);
            set12ItemBaseData(weight, fat, bmi, bmr, vf,
                    muscleMass, boneMass, protein, waterRate,
                    skeletalMuscle, bodyScore, bodyAge);
            return;//访客模式不需要上传数据 直接显示就可以了
        }
        float currentWeight = UserSpUtil.readFloat(Constants.IUser.WEIGHT);
        ULog.i(TAG, "---------currentWeight--" + currentWeight);
        if (currentWeight!=0&&Math.abs(currentWeight - weight) >= 2) {
            ULog.i(TAG, "---------相差有2kg----");
            if (mWeighTipDialog != null) {
                mWeighTipDialog.cancel();
                mWeighTipDialog = null;
            }
            mWeighTipDialog = new WeighTipDialog(getActivity());
            mWeighTipDialog.setListener(new WeighTipDialog.ICancelOkBtListener() {
                @Override
                public void cancel(Dialog dialogView) {
                    dialogView.cancel();
                }

                @Override
                public void ok(Dialog dialogView) {
                    dialogView.cancel();
                    ToastUtil.show(R.string.Uploaded_successfully);//上传成功提示语
                   currentDisplayDataTime = ScaleBaseUtils.getTime(result.getMeasureTime());//记录一下当前显示的数据时间
                    setDisplayDbv(weight);
                    set12ItemBaseData(weight, fat, bmi, bmr, vf,
                            muscleMass, boneMass, protein, waterRate,
                            skeletalMuscle, bodyScore, bodyAge);
                    upLoadData(result, weight, bmi, bmr, fat, vf, muscleMass, boneMass, protein, waterRate, skeletalMuscle, bodyScore);
                }
            });
            mWeighTipDialog.show();
        } else {
            ULog.i(TAG, "---------相差没有2kg直接上传数据了----");
            ToastUtil.show(R.string.Uploaded_successfully);//上传成功提示语
            if (mWeighTipDialog != null) {
                mWeighTipDialog.cancel();
                mWeighTipDialog = null;
            }
            currentDisplayDataTime = ScaleBaseUtils.getTime(result.getMeasureTime());//记录一下当前显示的数据时间
            setDisplayDbv(weight);
            set12ItemBaseData(weight, fat, bmi, (int) bmr, vf,
                    muscleMass, boneMass, protein, waterRate,
                    skeletalMuscle, bodyScore, bodyAge);
            upLoadData(result, weight, bmi, bmr, fat, vf, muscleMass, boneMass, protein, waterRate, skeletalMuscle, bodyScore);
        }
    }



    private long currentDisplayDataTime;
    public void disHistoryMesureData(ScaleMeasureResult result){
        if (result==null) {
            return;
        }
        ULog.i(TAG,"disHistoryMesureData--"+result.toString());
        long currentDataTime=ScaleBaseUtils.getTime(result.getMeasureTime());
        if (currentDataTime<currentDisplayDataTime){
            return;//当前的离线数据时间在现在显示的数据时间之前就直接退出不用显示了
        }
        result = ScaleBaseUtils.checkScaleMeasureResult18old(result);
        final float weight = numFatmat(result.getWeight());
        if (weight <= 0) {
            return;//如果体重都等于0时就没必要往上传了
        }
        float fat = numFatmat(result.getFat());//脂肪率
        float bmi = numFatmat(result.getBmi());
        float bmr = numFatmat(result.getBmr());
        float vf = numFatmat(result.getVisceralFat());//内脂等级
        float muscleMass = numFatmat(result.getMuscleVolume());
        float boneMass = numFatmat(result.getBoneVolume());
        float protein = numFatmat(result.getProtein());
        float waterRate = numFatmat(result.getWaterRate());
        float skeletalMuscle = numFatmat(result.getSkeletalMuscle());
        int bodyScore = (int) result.getBodyScore();
        int bodyAge = (int) result.getBodyAge();
        currentDisplayDataTime = currentDataTime;
        ToastUtil.show(R.string.Offline_data_synced);//提示  离线数据同步完毕
        setDisplayDbv(weight);
        set12ItemBaseData(weight, fat, bmi, (int) bmr, vf,
                muscleMass, boneMass, protein, waterRate,
                skeletalMuscle, bodyScore, bodyAge);


    }

//
    private void upLoadData(final ScaleMeasureResult result, final float weight, final float bmi, final float bmr, final float fat, final float vf,
                            final float muscleMass, final float boneMass, final float protein, final float waterRate, final float skeletalMuscle, final int bodyScore) {
        //上传测量数据到后台
        Map<String, Serializable> paramMap = new HashMap<>();
        final long userId=UserSpUtil.readLong(Constants.IUser.USER_ID);
        paramMap.put(HttpsParameters.USER_ID,userId);
        paramMap.put(HttpsParameters.WEIGHT, result.getWeight());
        paramMap.put(HttpsParameters.BMI, bmi);
        paramMap.put(HttpsParameters.BMR, bmr);
        //  paramMap.put(HttpsParameters.VISCERAL_FAT, fat);//脂肪率
        paramMap.put(HttpsParameters.ADIPOSE_RATE, fat);//脂肪率
        paramMap.put(HttpsParameters.VISCERAL_FAT, vf);//内脂等级
        paramMap.put(HttpsParameters.MUSCLEQUANTITY, muscleMass);
        paramMap.put(HttpsParameters.BONEMASS, boneMass);
        paramMap.put(HttpsParameters.PROTEIN, protein);
        paramMap.put(HttpsParameters.MOISTURE, waterRate);//水分
        paramMap.put(HttpsParameters.BONEMINERALCONTENT, skeletalMuscle);//骨骼肌
        paramMap.put(HttpsParameters.BODY_SOCRE, bodyScore);
        final int bodyAge= (int) result.getBodyAge();
        paramMap.put(HttpsParameters.PHYSICA_AGE,bodyAge);
        paramMap.put(HttpsParameters.TEST_DATE, result.getMeasureTime());

        ULog.i(TAG, "上传的参数paramMap---" + mBaseJsonGenerator.getMapRJ(paramMap));

        NetUtils.getInstance().uploadData(mContext, paramMap, new HttpResponse<OriginalParametersResponse>() {
            @Override
            public void result(boolean isRequestSuccess, String requestDes, OriginalParametersResponse originalParametersResponse) {

                if (isRequestSuccess) {
                    if (originalParametersResponse.resultCode == 0) {
                        ULog.i(TAG, "-----上传测量数据----上传成功---");
                        UserSpUtil.writeFloat(Constants.IUser.WEIGHT, result.getWeight());//把最新的体重数据保存在本地
                        Activity activity = getActivity();
                        if (activity != null) {
                            ((MainActivity) activity).goalPagerUpdateCurrentWeight();//更新当前体重
                            ((MainActivity) activity).trendPagerRequestAvgData(false);//更新趋势界面的数据
                            //((MainActivity) activity).trendPagerUpdateTargetWeight();
                        }
                        return;

                    } else {
                        ULog.i(TAG, "-----上传测量数据----上传失败：" + originalParametersResponse.resultMessage);
                    }
                } else {
                    ULog.i(TAG, "-----上传测量数据----网络失败");
                }
                //把上传失败的数据保存在本地
                HistoryMesureDataDao.saveData(userId,result.getMeasureTime(),fat,weight,waterRate,bmr,vf,muscleMass,skeletalMuscle,boneMass,bmi,protein,bodyAge,bodyScore);
            }
        });

    }

    /**
     * 设置10项基本数据
     *
     * @param weight      体重
     * @param fat         脂肪
     * @param BMI         bmi
     * @param BMR         bmr
     * @param vesceralFat 内脂
     * @param muscleMass  肌肉质量
     * @param boneMass    骨量
     * @param protein     蛋白质
     * @param water       水分
     * @param skeleta     骨骼肌
     * @param bodyScore   身体分数
     * @param bodyAge     身体年龄
     */
    @SuppressLint("SetTextI18n")
    public void set12ItemBaseData(float weight, float fat, float BMI, int BMR, float vesceralFat,
                                  float muscleMass, float boneMass, float protein, float water, float skeleta, int bodyScore, int bodyAge) {

        weight = NumUtils.numBaoLiuWei(ScaleBaseUtils.adapterDataFloat(weight), 1);
        muscleMass = NumUtils.numBaoLiuWei(ScaleBaseUtils.adapterDataFloat(muscleMass), 1);
        boneMass = NumUtils.numBaoLiuWei(ScaleBaseUtils.adapterDataFloat(boneMass), 1);
        skeleta = NumUtils.numBaoLiuWei(ScaleBaseUtils.adapterDataFloat(skeleta), 1);
        vesceralFat = NumUtils.numBaoLiuWei(vesceralFat, 1);

        setBmr(BMR,StringUtils.getResStr(R.string.kcal_d));
        set12ItemBaseData(strFatmat(weight, Constants.isKgUnit ? KG : LB),
                strFatmat2(fat, P),
                strFatmat(BMI, NON),
                strFatmat2(BMR, KCAL),
                strFatmat(vesceralFat, NON),
                strFatmat(muscleMass, Constants.isKgUnit ? KG : LB),
                strFatmat(boneMass, Constants.isKgUnit ? KG : LB),
                strFatmat2(protein, P),
                strFatmat2(water, P),
                strFatmat(skeleta, Constants.isKgUnit ? KG : LB),
                strFatmat(bodyScore, NON), strFatmat(bodyAge, NON));
    }



    private String KG = StringUtils.getResStr(R.string.kg);
    private String LB = StringUtils.getResStr(R.string.lb);
    private static final String KCAL = StringUtils.getResStr(R.string.kcal_d);
    private static final String NON = "";
    private static final String P = "%";

    private String strFatmat(float value, String unit) {
        if (value <= 0) {
            return NO_RESULT;
        }
        if (TextUtils.equals(unit,LB)){
            return ScaleBaseUtils.unitDisplay2(value+"",unit);
        }else {
            return ScaleBaseUtils.unitDisplay(value,unit);
        }


    }

    private String strFatmat2(float value, String unit) {
        if (value <= 0) {
            return NO_RESULT;
        }
        //return value + unit;
        return ScaleBaseUtils.unitDisplay2(value+"",unit);
    }

    private String strFatmat(int value, String unit) {
        if (value <= 0) {
            return NO_RESULT;
        }
        return value + unit;
    }


    public void set12ItemBaseData(String weight, String fat, String BMI, String BMR, String vesceralFat,
                                  String muscleMass, String boneMass, String protein, String water, String skeleta,
                                  String bodyScore, String bodyAge) {
        if (tvWeight != null) tvWeight.setText(weight);
        if (tvFat != null) tvFat.setText(fat);
        if (tvBmi != null) tvBmi.setText(BMI);
       // if (tvBmr != null) tvBmr.setText(BMR);

        if (tvVfl != null) tvVfl.setText(vesceralFat);
        if (tvMv != null) tvMv.setText(muscleMass);
        if (tvBv != null) tvBv.setText(boneMass);
        if (tvProtein != null) tvProtein.setText(protein);
        if (tvWr != null) tvWr.setText(water);
        if (tvSkeletal != null) tvSkeletal.setText(skeleta);
        if (tvBodyScore != null) tvBodyScore.setText(bodyScore);
        if (tvBodyAge != null) tvBodyAge.setText(bodyAge);

    }

    private void setBmr(float value, String unit){
        StringUtils.setTextUseSpannable(tvBmr, (int) value,unit,28);
    }

    public static final String NO_RESULT = "--";

    public void onNoResult() {
        setDisplayDbv(0);
        set12ItemBaseData(NO_RESULT, NO_RESULT, NO_RESULT, NO_RESULT, NO_RESULT, NO_RESULT, NO_RESULT, NO_RESULT, NO_RESULT, NO_RESULT, NO_RESULT, NO_RESULT);
    }

    private void setDisplayDbv(float value) {
        float currentWeight2 = UserSpUtil.readFloat(Constants.IUser.WEIGHT);
        ULog.i(TAG, "dbv-当前的体重是---currentWeight2=" + currentWeight2);
        if (dbv!=null&&dbv.displayValue == 0) {//说明是第一次进来
            float currentWeight = UserSpUtil.readFloat(Constants.IUser.WEIGHT);
            dbv.setDisplayValue(currentWeight);
            dbv3_lb.setDisplayValue(ScaleBaseUtils.adapterDataFloat(currentWeight));
            ULog.i(TAG, "dbv-说明是第一次进来---currentWeight=" + currentWeight);
        }
        if (Constants.isKgUnit) {
            ViewUtils.hideView(dbv3_lb);
            ViewUtils.displayView(dbv);
            if (dbv != null) {
                dbv.isDisplayFxjt = true;
                if (value < dbv.displayValue) {
                    dbv.isDisplayFxjt_XiangShang = false;
                } else if (value > dbv.displayValue) {
                    dbv.isDisplayFxjt_XiangShang = true;
                } else if (value == dbv.displayValue) {
                    dbv.isDisplayFxjt = false;
                    ULog.i(TAG, "value==dbv.displayValue是一样的，准备不显示箭头 value=" + value);
                }
                if (Constants.isGuestModel) {
                    dbv.isDisplayFxjt = false;
                    ULog.i(TAG, "访客模式，准备不显示箭头");
                }
                dbv.setDisplayValue(value);
                dbv.show();
            }

        }else {
            ViewUtils.displayView(dbv3_lb);
            ViewUtils.hideView(dbv);
            if (dbv3_lb != null) {
                dbv3_lb.isDisplayFxjt = true;
                value=ScaleBaseUtils.adapterDataFloat(value);
                if (value < dbv3_lb.displayValue) {
                    dbv3_lb.isDisplayFxjt_XiangShang = false;
                } else if (value > dbv3_lb.displayValue) {
                    dbv3_lb.isDisplayFxjt_XiangShang = true;
                } else if (value == dbv3_lb.displayValue) {
                    dbv3_lb.isDisplayFxjt = false;
                    ULog.i(TAG, "value==dbv.displayValue是一样的，准备不显示箭头 value=" + value);
                }
                if (Constants.isGuestModel) {
                    dbv3_lb.isDisplayFxjt = false;
                    ULog.i(TAG, "访客模式，准备不显示箭头");
                }
                dbv3_lb.setDisplayValue(value);
                dbv3_lb.show();
            }
        }
    }



    public void setDashboardPagerConnectImage(final boolean connectedFlag) {
        if (myHandle!=null){
            myHandle.post(new Runnable() {
                @Override
                public void run() {
                    if (!connectedFlag){
                        ViewUtils.displayView(iv_title_dashboard_pager);
                        ViewUtils.setImageResource(iv_title_dashboard_pager,R.drawable.ic_disconnected);
                    }else {
                        startShanAnimation();
                    }
                }
            });
        }

    }


    private int animationIndex=0;
    private MyHandle myHandle;
    private void startShanAnimation() {
        animationIndex=0;
        ViewUtils.setImageResource(iv_title_dashboard_pager,R.drawable.ic_connected);
        nextAnimation();
    }

    private void nextAnimation() {
        if (animationIndex==1||animationIndex==3||animationIndex==5){
            ViewUtils.hideView(iv_title_dashboard_pager);
        }else {
            ViewUtils.displayView(iv_title_dashboard_pager);
        }
        animationIndex++;
        if (animationIndex<7){
            myHandle.sendEmptyMessageDelayed(AnimationNext,250);
        }

    }

    private static final int AnimationNext = 1;
    class MyHandle extends Handler{
        MyHandle() {
            super(Looper.getMainLooper());
        }
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what==AnimationNext){

                nextAnimation();
            }
        }
    }
}